<%@page import="classes.User"%>
<%@page import="classes.AccountManager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit User</title>
</head>
<body>

<%
	AccountManager accManager = (AccountManager)application.getAttribute(AccountManager.ACCOUNTMANAGER);
	
	String username = request.getParameter("user");
	if(username != null){
		out.println("Change values and hit submit button to save changes");
		
		username = username.substring(0, username.indexOf(' '));	
		User user = accManager.getUser(username);	
		
		out.println("<form action=\"editUser.jsp\">");
		out.println("<p>username: <input type=\"text\" name=\"username\" value=" + user.getUserName() + "></p>");		
		out.println("<p>name: <input type=\"text\" name=\"name\" value=" + user.getName() + "></p>");
		out.println("<p>surname: <input type=\"text\" name=\"surname\" value=" + user.getSurName() + "></p>");
		out.println("<p>status: <input type=\"text\" name=\"status\" value=" + user.getStatus() + "></p>");
		out.println("<p>info: <input type=\"text\" name=\"info\" value=" + user.getInfo() + "></p>");
		out.println("<p>pic: <input type=\"text\" name=\"pic\" value=" + user.getPic() + "></p>");
	
		out.println("<input type=\"hidden\" name=\"oldUsername\" value=" + username + ">");
		out.println("<input type=\"submit\">");
		out.println("</form>");
	}
	else{
		User user = accManager.getUser(request.getParameter("oldUsername"));
		user.setUserName(request.getParameter("username"));
		user.setName(request.getParameter("name"));
		user.setSurName(request.getParameter("surname"));
		user.setStatus(request.getParameter("status"));
		user.setInfo(request.getParameter("info"));
		user.setPic(request.getParameter("pic"));
		
		
		out.println("<form action=\"editUser.jsp\">");
		out.println("<p>username: <input type=\"text\" name=\"username\" value=" + user.getUserName() + "></p>");		
		out.println("<p>name: <input type=\"text\" name=\"name\" value=" + user.getName() + "></p>");
		out.println("<p>surname: <input type=\"text\" name=\"surname\" value=" + user.getSurName() + "></p>");
		out.println("<p>status: <input type=\"text\" name=\"status\" value=" + user.getStatus() + "></p>");
		out.println("<p>info: <input type=\"text\" name=\"info\" value=" + user.getInfo() + "></p>");
		out.println("<p>pic: <input type=\"text\" name=\"pic\" value=" + user.getPic() + "></p>");
	
		out.println("<input type=\"hidden\" name=\"oldUsername\" value=" + username + ">");
		out.println("<input type=\"submit\">");
		out.println("</form>");
		
		
		out.println("changes saved");
		out.println("<br>");
	}
	
	out.println("<a href=\"adminLogin.jsp\">go to home page</a>");
%>


		






</body>
</html>